home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / JDialog.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  6.5 KB  |  285 lines

  1. package javax.swing;
  2.  
  3. import java.applet.Applet;
  4. import java.awt.AWTEvent;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.Dialog;
  8. import java.awt.Dimension;
  9. import java.awt.Frame;
  10. import java.awt.Graphics;
  11. import java.awt.LayoutManager;
  12. import java.awt.Point;
  13. import java.awt.Rectangle;
  14. import java.awt.Window;
  15. import java.awt.event.InputEvent;
  16. import java.awt.event.KeyEvent;
  17. import java.awt.event.WindowEvent;
  18. import javax.accessibility.Accessible;
  19. import javax.accessibility.AccessibleContext;
  20.  
  21. public class JDialog extends Dialog implements WindowConstants, Accessible, RootPaneContainer {
  22.    private int defaultCloseOperation;
  23.    protected JRootPane rootPane;
  24.    protected boolean rootPaneCheckingEnabled;
  25.    protected AccessibleContext accessibleContext;
  26.  
  27.    public JDialog() {
  28.       this((Frame)null, false);
  29.    }
  30.  
  31.    public JDialog(Frame var1) {
  32.       this(var1, false);
  33.    }
  34.  
  35.    public JDialog(Frame var1, String var2) {
  36.       this(var1, var2, false);
  37.    }
  38.  
  39.    public JDialog(Frame var1, String var2, boolean var3) {
  40.       super(var1 == null ? SwingUtilities.getSharedOwnerFrame() : var1, var2, var3);
  41.       this.defaultCloseOperation = 1;
  42.       this.rootPaneCheckingEnabled = false;
  43.       this.accessibleContext = null;
  44.       this.dialogInit();
  45.    }
  46.  
  47.    public JDialog(Frame var1, boolean var2) {
  48.       this(var1, (String)null, var2);
  49.    }
  50.  
  51.    protected void addImpl(Component var1, Object var2, int var3) {
  52.       if (this.isRootPaneCheckingEnabled()) {
  53.          throw this.createRootPaneException("add");
  54.       } else {
  55.          super.addImpl(var1, var2, var3);
  56.       }
  57.    }
  58.  
  59.    protected JRootPane createRootPane() {
  60.       return new JRootPane();
  61.    }
  62.  
  63.    private Error createRootPaneException(String var1) {
  64.       String var2 = this.getClass().getName();
  65.       return new Error("Do not use " + var2 + "." + var1 + "() use " + var2 + ".getContentPane()." + var1 + "() instead");
  66.    }
  67.  
  68.    protected void dialogInit() {
  69.       ((Component)this).enableEvents(72L);
  70.       this.setRootPane(this.createRootPane());
  71.       this.setRootPaneCheckingEnabled(true);
  72.    }
  73.  
  74.    public AccessibleContext getAccessibleContext() {
  75.       if (this.accessibleContext == null) {
  76.          this.accessibleContext = new AccessibleJDialog(this);
  77.       }
  78.  
  79.       return this.accessibleContext;
  80.    }
  81.  
  82.    public Container getContentPane() {
  83.       return this.getRootPane().getContentPane();
  84.    }
  85.  
  86.    public int getDefaultCloseOperation() {
  87.       return this.defaultCloseOperation;
  88.    }
  89.  
  90.    public Component getGlassPane() {
  91.       return this.getRootPane().getGlassPane();
  92.    }
  93.  
  94.    public JMenuBar getJMenuBar() {
  95.       return this.getRootPane().getMenuBar();
  96.    }
  97.  
  98.    public JLayeredPane getLayeredPane() {
  99.       return this.getRootPane().getLayeredPane();
  100.    }
  101.  
  102.    public JRootPane getRootPane() {
  103.       return this.rootPane;
  104.    }
  105.  
  106.    protected boolean isRootPaneCheckingEnabled() {
  107.       return this.rootPaneCheckingEnabled;
  108.    }
  109.  
  110.    protected String paramString() {
  111.       String var1;
  112.       if (this.defaultCloseOperation == 1) {
  113.          var1 = "HIDE_ON_CLOSE";
  114.       } else if (this.defaultCloseOperation == 2) {
  115.          var1 = "DISPOSE_ON_CLOSE";
  116.       } else if (this.defaultCloseOperation == 0) {
  117.          var1 = "DO_NOTHING_ON_CLOSE";
  118.       } else if (this.defaultCloseOperation == 3) {
  119.          var1 = "EXIT_ON_CLOSE";
  120.       } else {
  121.          var1 = "";
  122.       }
  123.  
  124.       String var2 = this.rootPane != null ? this.rootPane.toString() : "";
  125.       String var3 = this.rootPaneCheckingEnabled ? "true" : "false";
  126.       return super.paramString() + ",defaultCloseOperation=" + var1 + ",rootPane=" + var2 + ",rootPaneCheckingEnabled=" + var3;
  127.    }
  128.  
  129.    protected void processKeyEvent(KeyEvent var1) {
  130.       super.processKeyEvent(var1);
  131.       if (!((InputEvent)var1).isConsumed()) {
  132.          JComponent.processKeyBindingsForAllComponents(var1, this, ((AWTEvent)var1).getID() == 401);
  133.       }
  134.  
  135.    }
  136.  
  137.    protected void processWindowEvent(WindowEvent var1) {
  138.       super.processWindowEvent(var1);
  139.       if (((AWTEvent)var1).getID() == 201) {
  140.          switch (this.defaultCloseOperation) {
  141.             case 0:
  142.             default:
  143.                break;
  144.             case 1:
  145.                ((Component)this).setVisible(false);
  146.                break;
  147.             case 2:
  148.                ((Component)this).setVisible(false);
  149.                ((Window)this).dispose();
  150.                break;
  151.             case 3:
  152.                System.exit(0);
  153.          }
  154.       }
  155.  
  156.    }
  157.  
  158.    public void remove(Component var1) {
  159.       if (var1 == this.rootPane) {
  160.          super.remove(var1);
  161.       } else {
  162.          this.getContentPane().remove(var1);
  163.       }
  164.  
  165.    }
  166.  
  167.    public void setContentPane(Container var1) {
  168.       this.getRootPane().setContentPane(var1);
  169.    }
  170.  
  171.    public void setDefaultCloseOperation(int var1) {
  172.       this.defaultCloseOperation = var1;
  173.    }
  174.  
  175.    public void setGlassPane(Component var1) {
  176.       this.getRootPane().setGlassPane(var1);
  177.    }
  178.  
  179.    public void setJMenuBar(JMenuBar var1) {
  180.       this.getRootPane().setMenuBar(var1);
  181.    }
  182.  
  183.    public void setLayeredPane(JLayeredPane var1) {
  184.       this.getRootPane().setLayeredPane(var1);
  185.    }
  186.  
  187.    public void setLayout(LayoutManager var1) {
  188.       if (this.isRootPaneCheckingEnabled()) {
  189.          throw this.createRootPaneException("setLayout");
  190.       } else {
  191.          super.setLayout(var1);
  192.       }
  193.    }
  194.  
  195.    public void setLocationRelativeTo(Component var1) {
  196.       Container var2 = null;
  197.       if (var1 != null) {
  198.          if (!(var1 instanceof Window) && !(var1 instanceof Applet)) {
  199.             for(Container var3 = var1.getParent(); var3 != null; var3 = ((Component)var3).getParent()) {
  200.                if (var3 instanceof Window || var3 instanceof Applet) {
  201.                   var2 = var3;
  202.                   break;
  203.                }
  204.             }
  205.          } else {
  206.             var2 = (Container)var1;
  207.          }
  208.       }
  209.  
  210.       if ((var1 == null || var1.isShowing()) && var2 != null && ((Component)var2).isShowing()) {
  211.          Dimension var10 = var1.getSize();
  212.          Point var11;
  213.          if (var2 instanceof Applet) {
  214.             var11 = var1.getLocationOnScreen();
  215.          } else {
  216.             var11 = new Point(0, 0);
  217.  
  218.             for(Object var5 = var1; var5 != null; var5 = ((Component)var5).getParent()) {
  219.                Point var6 = ((Component)var5).getLocation();
  220.                var11.x += var6.x;
  221.                var11.y += var6.y;
  222.                if (var5 == var2) {
  223.                   break;
  224.                }
  225.             }
  226.          }
  227.  
  228.          Rectangle var12 = ((Component)this).getBounds();
  229.          int var13 = var11.x + (var10.width - var12.width >> 1);
  230.          int var7 = var11.y + (var10.height - var12.height >> 1);
  231.          Dimension var8 = ((Window)this).getToolkit().getScreenSize();
  232.          if (var7 + var12.height > var8.height) {
  233.             var7 = var8.height - var12.height;
  234.             var13 = var11.x < var8.width >> 1 ? var11.x + var10.width : var11.x - var12.width;
  235.          }
  236.  
  237.          if (var13 + var12.width > var8.width) {
  238.             var13 = var8.width - var12.width;
  239.          }
  240.  
  241.          if (var13 < 0) {
  242.             var13 = 0;
  243.          }
  244.  
  245.          if (var7 < 0) {
  246.             var7 = 0;
  247.          }
  248.  
  249.          ((Component)this).setLocation(var13, var7);
  250.       } else {
  251.          Dimension var9 = ((Component)this).getSize();
  252.          Dimension var4 = ((Window)this).getToolkit().getScreenSize();
  253.          ((Component)this).setLocation((var4.width - var9.width) / 2, (var4.height - var9.height) / 2);
  254.       }
  255.  
  256.    }
  257.  
  258.    protected void setRootPane(JRootPane var1) {
  259.       if (this.rootPane != null) {
  260.          this.remove(this.rootPane);
  261.       }
  262.  
  263.       this.rootPane = var1;
  264.       if (this.rootPane != null) {
  265.          boolean var2 = this.isRootPaneCheckingEnabled();
  266.  
  267.          try {
  268.             this.setRootPaneCheckingEnabled(false);
  269.             ((Container)this).add(this.rootPane, "Center");
  270.          } finally {
  271.             this.setRootPaneCheckingEnabled(var2);
  272.          }
  273.       }
  274.  
  275.    }
  276.  
  277.    protected void setRootPaneCheckingEnabled(boolean var1) {
  278.       this.rootPaneCheckingEnabled = var1;
  279.    }
  280.  
  281.    public void update(Graphics var1) {
  282.       ((Container)this).paint(var1);
  283.    }
  284. }
  285.